import {ModalForm, ProFormSelect, ProFormText} from "@ant-design/pro-components";
import {useRef} from "react";
import {ProFormInstance} from "@ant-design/pro-form/lib";
import {RequestOptionsType} from "@ant-design/pro-utils";
import {useModel, useSnapshot} from "@@/exports";
import {ActivityAwardModel} from "@/models/activityAward";


export interface ActivityAwardUpdateModalProps {
    onFinish: (formData: any) => Promise<boolean | void>;
}

const ActivityAwardUpdateModal = (props: ActivityAwardUpdateModalProps) => {
    let {getDictList} = useModel("dict");
    let activityAwardState = useSnapshot(ActivityAwardModel.state);
    let {actions: activityAwardActions} = ActivityAwardModel
    const formRef = useRef<ProFormInstance>()
    return <>
        <ModalForm
            key={activityAwardState.activityAward?.id || -1}
            formRef={formRef}
            title={activityAwardState.activityAward ? "修改活动奖品" : "添加活动奖品"}
            open={activityAwardState.updateModalState}
            initialValues={activityAwardState.activityAward}
            onFinish={props.onFinish}
            onOpenChange={activityAwardActions.setUpdateModalState}
        >
            <ProFormText
                label="奖品id"
                hidden
                name="id"
                rules={[{required: true, message: "请填写奖品id"}]}
            />
            <ProFormText
                label="奖品名"
                name="awardName"
                rules={[{required: true, message: "请填写奖品名"}]}
            />
            <ProFormText
                label="奖品图片"
                name="awardHeadImg"
                rules={[{required: true, message: "请填写奖品图片"}]}
            />
            <ProFormSelect
                label="领取规则"
                name="receiveRule"
                request={async () => getDictList('bh_award_receive_rule') as RequestOptionsType[]}
                rules={[{required: true, message: "请选择领取规则"}]}
            />
            <ProFormText
                label="领取限制"
                name="receiveLimit"
                rules={[{required: true, message: "请填写领取限制"}]}
            />


        </ModalForm>
    </>
}

export default ActivityAwardUpdateModal
